package com.bosssoft.user.permission.center.serve.controller;



import com.bosssoft.user.permission.center.serve.api.RoleApi;
import com.bosssoft.user.permission.center.serve.pojo.dto.*;
import com.bosssoft.user.permission.center.serve.pojo.query.RoleQuery;
import com.bosssoft.user.permission.center.serve.pojo.query.RoleUserQuery;
import com.bosssoft.user.permission.center.serve.pojo.vo.RoleCompanyVO;
import com.bosssoft.user.permission.center.serve.pojo.vo.RoleUserVO;
import com.bosssoft.user.permission.center.serve.pojo.vo.RoleVO;
import com.bosssoft.user.permission.center.serve.service.RoleService;

import common.data.commonresponse.CommonPage;
import common.data.commonresponse.CommonResponse;
import common.util.CommonResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleController implements RoleApi {


    @Autowired

    RoleService roleService;


    @Override
    public CommonResponse<CommonPage<RoleVO>> search(RoleQuery roleQuery) {
        return CommonResponseUtils.success(roleService.search(roleQuery));
    }

    @Override
    public CommonResponse<Boolean> add(RoleDTO roleDTO) {
        return CommonResponseUtils.booleanResult(roleService.add(roleDTO));
    }

    @Override
    public CommonResponse<Boolean> update(RoleDTO roleDTO) {
        return CommonResponseUtils.booleanResult(roleService.update(roleDTO));
    }

    @Override
    public CommonResponse<Boolean> remove(List<Long> ids) {
        return CommonResponseUtils.booleanResult(roleService.remove(ids));
    }

    @Override
    public CommonResponse<String>  checkRoleCode(String code,Long roleId) {
        return CommonResponseUtils.success(roleService.checkRoleCode(code,roleId));
    }


    @Override
    public CommonResponse<Boolean> allocateResource(RoleResourceDTO roleResourceDTO) {
        return CommonResponseUtils.booleanResult(roleService.allocateResource(roleResourceDTO));
    }

    @Override
    public CommonResponse<Boolean> allocateResourceAndCompany(RoleResourceAndCompanyDTO roleResourceAndCompanyDTO) {
        return CommonResponseUtils.booleanResult(roleService.allocateResourceAndCompany(roleResourceAndCompanyDTO));
    }

    @Override
    public CommonResponse<String> checkRoleIfHavingResource(Long roleId) {
        return CommonResponseUtils.success(roleService.checkRoleIfHavingResource(roleId));
    }

    @Override
    public CommonResponse<List<RoleCompanyVO>> checkRoleCompany(List<Long> roleIds) {
        return CommonResponseUtils.success(roleService.checkRoleCompany(roleIds));
    }

    @Override
    public CommonResponse<CommonPage<RoleUserVO>> checkRoleUser(RoleUserQuery roleUserQuery) {
        return CommonResponseUtils.success(roleService.checkRoleUser(roleUserQuery));
    }

    @Override
    public CommonResponse<Boolean> allocateCompany(RoleCompanyDTO roleCompanyDTO) {
        return CommonResponseUtils.booleanResult(roleService.allocateCompany(roleCompanyDTO));
    }


    @Override
    public CommonResponse<Boolean> allocateUser (RoleUserDTO roleUserDTO) {
        return CommonResponseUtils.booleanResult(roleService.allocateUser(roleUserDTO));
    }


    @Override
    public CommonResponse<Object> showRoleResource(RoleResourceCheckDTO roleResourceCheckDTO) {

        return CommonResponseUtils.success(roleService.showRoleResource(roleResourceCheckDTO));
    }
}
